package com.bdc.base;

import com.bdc.memory.domain.RecordInfo;
import com.bdc.memory.webservice.IBdcWebService;
import com.bdc.memory.webservice.impl.IBdcWebServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.binding.http.HttpBindingFactory;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.service.invoker.BeanInvoker;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;

import javax.servlet.ServletConfig;
import javax.xml.ws.Endpoint;

/**
 * User: Shawn
 * Date: 2011-6-14
 * Time: 9:59:20
 */
public class CxfServlet extends CXFNonSpringServlet {

    @Override
    protected void loadBus(ServletConfig sc) {
        super.loadBus(sc);

        Bus bus = getBus();
        BusFactory.setDefaultBus(bus);
        IBdcWebServiceImpl bdcService = new IBdcWebServiceImpl();
        Endpoint.publish("/bdc", bdcService);

        JAXRSServerFactoryBean restServer = new JAXRSServerFactoryBean();
        restServer.setBus(bus);
        restServer.setResourceClasses(RecordInfo.class);
        restServer.setServiceBean(bdcService);
        restServer.setAddress("/rest");
        restServer.create();
    }
}
